package com.skywo.demo1.common.security

import com.alibaba.fastjson2.JSON
import com.skywo.demo1.common.result.RF
import com.skywo.demo1.common.result.ResultCode
import org.springframework.security.core.AuthenticationException
import org.springframework.security.web.AuthenticationEntryPoint
import java.io.IOException
import javax.servlet.ServletException
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

class MyAuthenticationEntryPoint : AuthenticationEntryPoint {
    @Throws(IOException::class, ServletException::class)
    override fun commence(
        request: HttpServletRequest?,
        response: HttpServletResponse,
        authException: AuthenticationException?
    ) {
        //返回响应
        response.setContentType("application/json;charset=UTF-8")
        response.getWriter().println(JSON.toJSONString(RF.fail(ResultCode.NOT_LOGIN)))
    }
}